local balancer = require "ngx.balancer";

local consulServiceStore = ngx.shared.consul_store

local serviceName = ngx.ctx.serviceName

--JSON处理器
local cjs = require "cjson.safe";

local consulServiceUrlMap = cjs.decode(consulServiceStore:get('consulServiceUrlMap'));

ngx.log(ngx.ERR, "router-filter call address:  ", consulServiceUrlMap[serviceName][1])

ngx.log(ngx.ERR, "router-filter call port", consulServiceUrlMap[serviceName][2])

--JOSN解析成功 调整到对应的ip port  consul地址都是容器地址 先配置一个本地服务
local ok, err = balancer.set_current_peer("127.0.0.1",19008);

if not ok then
    ngx.log(ngx.ERR, "failed to set peer: ",err);
    return ngx.exit(500);
end;

ngx.log(ngx.ERR, "set_current_peer ok", ok," ;  ")
